package com.pxst.internalReports.service.impl;

import com.pxst.internalReports.entity.SysVrEntity;
import com.pxst.internalReports.mapper.SysVrEntityMapper;
import com.pxst.internalReports.resp.ApprovedAccResp;
import com.pxst.internalReports.service.SysVrEntityService;
import com.pxst.merchant.entity.SysMerchantInfo;
import com.pxst.merchant.mapper.SysMerchantInfoMapper;
import com.pxst.resp.ApiResp;
import icu.mhb.mybatisplus.plugln.base.service.impl.JoinServiceImpl;
import icu.mhb.mybatisplus.plugln.core.JoinLambdaWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Chrissy
 * @description SysVrEntity对应的serviceImpl
 * @since 2023-11-13 15:17:23
 */
@Service
public class SysVrEntityServiceImpl extends JoinServiceImpl<SysVrEntityMapper, SysVrEntity> implements SysVrEntityService {
    @Resource
    private SysVrEntityMapper sysVrEntityMapper;

    @Override
    public ApiResp searchApprovedAcc(String number) {


        JoinLambdaWrapper<SysVrEntity> jlw = new JoinLambdaWrapper<>(SysVrEntity.class);
        jlw.eq(!ObjectUtils.isEmpty(number), SysVrEntity::getNumber, number)
                .selectAs(sve -> {
                    sve
                            .addFunAlias(SysVrEntity::getNumber, ApprovedAccResp::getNumber)
                            .addFunAlias(SysVrEntity::getBank, ApprovedAccResp::getBank)
                            .addFunAlias(SysVrEntity::getType, ApprovedAccResp::getType)
                            .addFunAlias(SysVrEntity::getRequestedName, ApprovedAccResp::getRequestedName)
                            .addFunAlias(SysVrEntity::getMatchedNames, ApprovedAccResp::getMatchedNames)
                            .addFunAlias(SysVrEntity::getRequests, ApprovedAccResp::getRequests)
                            .addFunAlias(SysVrEntity::getCreatedAt, ApprovedAccResp::getCreatedAt)
                            .addFunAlias(SysVrEntity::getUpdatedAt, ApprovedAccResp::getUpdatedAt);
                });

        jlw.leftJoin(SysMerchantInfo.class, SysMerchantInfo::getId, SysVrEntity::getMerchantId)
                .selectAs(smi -> {
                    smi.addFunAlias(SysMerchantInfo::getName, ApprovedAccResp::getMerchantName);
                })
                .end();

        List<ApprovedAccResp> accResps = sysVrEntityMapper.joinSelectList(jlw, ApprovedAccResp.class);
        return ApiResp.sucess(accResps);
    }
}
